package br.com.colegio.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class FileUtil
{
	public static String streamToString(InputStream is, String separador) throws IOException
	{
		return bufferToString(new BufferedReader(new InputStreamReader(is)), separador);
	}

	public static String fileToString(File f, String separador) throws IOException
	{
		return bufferToString(new BufferedReader(new FileReader(f)), separador);
	}

	public static String fileToString(FileReader fr) throws IOException
	{
		return bufferToString(new BufferedReader(fr), "");
	}

	public static String bufferToString(BufferedReader br, String separador) throws IOException
	{
		StringBuilder sb = new StringBuilder();
		String ln = null;

		while ((ln = br.readLine()) != null)
			sb.append(ln + separador);

		br.close();

		return sb.toString();
	}

	public static String pegaURL(String u) throws IOException
	{
		return pegaURL(u, "");
	}

	public static String pegaURL(String u, String separador) throws IOException
	{
		return FileUtil.fileToString(new File(u), separador);
	}

	public static void main(String[] args)
	{
		try
		{
			System.out.println(fileToString(new File("E:/_/lingoo/_/interfilmes/filmes/b.html"), "\n"));
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}
